<?php

//是否已设置头像
function isSetAvatar($uid){
    return is_file( SITE_PATH.'/data/uploads/avatar/'.$uid.'/small.jpg');
}

//获取微博条数
function getMiniNum($uid){
	return M('weibo')->where('uid=' . $uid . ' AND isdel=0')->count();
}

//获取关注数
function getUserFollow($uid){
	$count['following'] = M('weibo_follow')->where("uid=$uid AND type=0")->count();
	$count['follower']  = M('weibo_follow')->where("fid=$uid AND type=0")->count();
	return $count;
}

// 短地址
function getContentUrl($url) {
	return getShortUrl( $url[1] ).' ';
}

// 登陆页微博表情解析
function login_emot_format($content)
{
    return preg_replace_callback('/(?:#[^#]*[^#^\s][^#]*#|(\[.+?\]))/is', 'replaceEmot', $content);
}



//获取家庭成员配置
function getFamilyConfig($key=NULL){
    $userRoles =  D('UserRole', 'home')->getUserRoles('role_id ASC');
    $defaultAvatar = array(
            	               //0 => array('宝贝', 'a_son_128.png'),
            	               1 => 'a_father_128.png',
            	               2 => 'a_mather_128.png',
            	               3 => 'a_gfather_128.png',
            	               4 => 'a_gmather_128.png',
            	               5 => 'a_gfather2_128.png',
            	               6 => 'a_gmather2_128.png',
            	           );
    $relation = array();
    foreach ($userRoles as $v) {
        $relation[$v['role_id']] = array($v['role_name'], $defaultAvatar[$v['role_id']]);
    }
    $config = array(
                 'relation' => $relation,
                 'duty'     => array(
                                   0 => '看着我长大',
                                   1 => '家长',
                                   2 => '主妇',
                                   3 => '教育',
                                   4 => '生活',
                               ),
	            );

    if (isset($key) && isset($config[$key])) {
        return $config[$key];
    } else {
        return $config;
    }

}

/**
 * author liuxp
 * date $Id: common.php 74 2012-05-06 09:46:14Z liuxp1981@gmail.com $
 * 获取用户家庭关系选项
 *
 * @param int $parent    要选中的选项值
 * @return  string
 */
function getRelationOption($parent=null) {

    $config = getFamilyConfig();
    $relation = $config['relation'];
    $option = '';
    foreach ($relation as $k => $v ) {
        if ($parent == $k) {
            $option .= "<option selected value=\"{$k}\">{$v[0]}</option>";
        } else {
            $option .= "<option value=\"{$k}\">{$v[0]}</option>";
        }
    }

    return $option;
}


